package com.ynny.service.impl;

import com.ynny.dao.BookDao;
import com.ynny.dao.UserDao;
import com.ynny.entity.Book;
import com.ynny.entity.User;
import com.ynny.service.BookManagerService;
import com.ynny.service.BookService;
import com.ynny.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    BookManagerService bookManagerService;

    @Autowired
    UserService userService;

    @Transactional
    @Override
    public int buyBook(Integer userId, Integer bookId) {
        //检查图书
        int price = bookManagerService.checkBook(bookId);
        //检查用户
        int res = userService.checkUser(userId, price);
        return res;

    }



}
